package com.nondo.dean.platform.service;

import com.nondo.dean.platform.domain.Attach;
import com.nondo.dean.platform.mapper.AttachMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ken.
 * @version 1.0
 * @email 695093513@qq.com
 * @date 2018/4/8
 */
@Component
public class AttachService {
    @Autowired
    AttachMapper attachMapper;

    /**
     * 获取单个附件信息
     *
     * @param id
     * @return
     */
    public Attach getById(int id) {
        Attach attach = this.attachMapper.selectByPrimaryKey(id);
        return attach;
    }

    /**
     * 通过附件ID列表获取列表
     *
     * @param listId
     * @return
     */
    public List<Attach> getList(List listId) {
        List list = new ArrayList();
        for (Object id : listId) {
            Attach attach = this.getById(Integer.parseInt(id.toString()));
            list.add(attach);
        }
        return list;
    }

    /**
     * 插入新的附件
     *
     * @param path
     * @return
     */
    public Attach insert(String path) {
        Attach attach = new Attach();
        attach.setPath(path);

        this.attachMapper.insertSelective(attach);

        return attach;
    }
}
